home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Garbo
/
Garbo.cdr
/
mac
/
cdev
/
clrnxtwd.sit
/
NeXT WDEF.c
< prev
next >
Wrap
C/C++ Source or Header
|
1989-11-10
|
15KB
|
468 lines
/*
╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
My Window Definition Procedure
╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
This handles that odd window.
╤╤╤╤╤╤╤╤
89/04/20
╤╤╤╤╤╤╤╤
1.0 89/03/31 First draft based on clock window def proc
(+A5 games).
89/04/05 Fixed problem with zoom box hilite
89/04/06 Fixed zooming
89/04/07 Minor changes in draw, chose from two gray patterns
to avoid odd mismatches in window dragged onscreen
from offscreen, added proper plainDBox & altDBoxProc
variations, special cased zero width titles.
1.1 89/04/09 Odd half erased scroll bar startup MPW adjusted
[see drawGrowIcon()]
1.2 89/04/09 Fixed problem with userState updates. Working on colors!
89/04/11 Changed size box to chevrons.
89/04/12 Made sure inGrow only returned on hilited windows.
89/04/20 Added Apples screenBits workaround and scroll area
to grow image.
2.0 89/11/10 Finished color additions and cleaned up other
assorted bugs. JNP
╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
Public Domain 1989 by Appropriate Technology
╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
Please send a copy of changes/improvements to:
Eric Celeste, Appropriate Technology, 358 North Parkview, Columbus, OH 43209, USA.
CompuServe: 76146,724. MacNET: Celeste.
╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
Note: This WDEF is coded in THINK C 4.0 from Think Technologies
╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
Changes made by Josh Pritikin (11.10.89):
1. In calculateMyWindow I added a test to see if we have a color window.
2. I removed the ugly StuffHex calls and speeded the pattern packing up.
3. I added a gunk of code and special casing to totally support ColorQD!
4. The code is admitably gross in some (most) places but it works and should
serve as an example of what not to make your code look like.
GEnie: J.Pritikin
AppleLink: D4991 (<- this will change soon)
Internet: 6500stom@ucsbuxa.ucsb.edu
*/
#include <Color.h>
#include <MacTypes.h>
#include <MemoryMgr.h>
#include <MenuMgr.h>
#include <OSUtil.h>
#include <Quickdraw.h>
#include <ToolboxUtil.h>
#include <WindowMgr.h>
#include <Global.h>
/*
╤╤╤╤╤╤╤╤╤
Constants
╤╤╤╤╤╤╤╤╤
*/
/* YOU ABSOLUTELY NEED TO DEFINE THIS WHEN YOUR RUNNING THE TESTER */
/* #define testing */
#define commandKeyCode 0x00008000 /* the keymap mask for the command key */
#define optionKeyCode 0x00000004 /* the keymap mask for the option key */
/*
╤╤╤╤╤
Types
╤╤╤╤╤
*/
typedef struct {
Rect userState, stdState;
Boolean buttonState;
} WSDRecord, *WSDPointer, **WSDHandle;
#define buttonState (**(WSDHandle)(*(WindowPeek)window).dataHandle).buttonState
#ifdef testing
pascal long nextWDEF( variation, window, message, parameter )
#else
pascal long main( variation, window, message, parameter )
#endif
short variation; /* variation code on this type window */
WindowPtr window; /* pointer to the window */
short message; /* what does the window manager want us to do? */
long parameter; /* parameter used for many things */
{
long result; /* the return code for the function */
long hitMyWindow(/* variation, window, parameter */);
#ifdef testing
SetUpA5();
#else /* this stuff lets us reference thePort, otherwise we don't need it */
/* RememberA0();
SetUpA4(); */
#endif
result = nil;
switch( message ) {
case( wDraw ):
drawMyWindow( variation, window, parameter );
break;
case( wHit ):
result = hitMyWindow( variation, window, parameter );
break;
case( wCalcRgns ):
calculateMyWindow( variation, window, parameter );
break;
case( wNew ):
setupWindow( variation, window, parameter );
break;
case( wDispose ):
killWindow( variation, window, parameter );
break;
case( wGrow ):
growMyWindow( variation, window, parameter );
break;
case( wDrawGIcon ):
drawGrowIcon( variation, window, parameter );
break;
}
#ifdef testing
RestoreA5();
#else
/* RestoreA4(); */
#endif
return( result );
}
/*╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
where was my window hit?
╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤*/
long hitMyWindow( variation, window, parameter )
short variation; /* variation code on this type window */
WindowPtr window; /* pointer to the window */
long parameter; /* parameter used for many things */
{
Point hitLocation;
Rect windowRect, thisRect;
long result;
result = wNoHit;
SetPt( &hitLocation, LoWord( parameter ), HiWord( parameter ) );
if ( PtInRgn( hitLocation, (*(WindowPeek)window).strucRgn ) ) {
windowRect = (**(*(WindowPeek)window).strucRgn).rgnBBox;
if ( PtInRgn( hitLocation, (*(WindowPeek)window).contRgn ) ) {
result = wInContent; /* in the content region */
if ( (*(WindowPeek)window).hilited ) {
if ( variation == documentProc || variation == (documentProc+8) ) {
SetRect( &thisRect,
windowRect.right - 16,
windowRect.bottom - 16,
windowRect.right - 4,
windowRect.bottom - 4
);
if ( PtInRect( hitLocation, &thisRect ) ) {
result = wInGrow;
}
}
}
} else {
result = wInDrag; /* in the drag area unless */
if ( (*(WindowPeek)window).hilited ) {
if ( (*(WindowPeek)window).goAwayFlag ) {
SetRect( &thisRect,
windowRect.left + 4,
windowRect.top + 4,
windowRect.left + 16,
windowRect.top + 16
);
if ( PtInRect( hitLocation, &thisRect ) ) {
result = wInGoAway;
}
}
if ( (result == wInDrag)
&& ( variation == documentProc || variation == (documentProc+8) )
) {
SetRect( &thisRect,
windowRect.right - 16,
windowRect.bottom - 16,
windowRect.right - 4,
windowRect.bottom - 4
);
if ( PtInRect( hitLocation, &thisRect ) ) {
result = wInGrow;
}
}
if ( (result == wInDrag)
&& (*(WindowPeek)window).spareFlag
) {
SetRect( &thisRect,
windowRect.right - 16,
windowRect.top + 4,
windowRect.right - 4,
windowRect.top + 16
);
if ( PtInRect( hitLocation, &thisRect ) ) {
if ( (*(WindowPeek)window).dataHandle != nil ) {
thisRect = (**(*(WindowPeek)window).contRgn).rgnBBox;
if ( EqualRect (
&((**(WSDHandle)(*(WindowPeek)window).dataHandle).stdState),
&thisRect
) ) {
result = wInZoomIn;
} else {
(**(WSDHandle)(*(WindowPeek)window).dataHandle).userState
= thisRect;
result = wInZoomOut;
}
} /* datahandle */
} /* in the zoom box */
} /* still dragging & zoomable */
} /* a hilited window */
} /* else not in content region */
} /* in the structure region */
return( result );
} /* end of hitMyWindow() */
/*╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
calculate the regions of my window
╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤*/
calculateMyWindow( variation, window, parameter )
short variation; /* variation code on this type window */
WindowPtr window; /* pointer to the window */
long parameter; /* parameter used for many things */
{
Rect windowRect, portR;
windowRect = (*window).portRect;
/* a fix for CWindowRecords */
if ((window->portBits.rowBytes & (3<<14)) == 0) {
OffsetRect( &windowRect, -window->portBits.bounds.left, -window->portBits.bounds.top );
} else {
portR = (**(*(CGrafPtr)window).portPixMap).bounds;
OffsetRect(&windowRect, -portR.left, -portR.top);
}
RectRgn( (*(WindowPeek)window).contRgn, &windowRect );
switch ( variation ) {
case ( documentProc + 8): /* a zooming window */
if (!EqualRect(&((**(WSDHandle)(*(WindowPeek)window).dataHandle).stdState),&windowRect)){
(**(WSDHandle)(*(WindowPeek)window).dataHandle).userState = windowRect;
}
case ( documentProc ): /* a regular window */
case ( noGrowDocProc ): /* a regular window with no growing */
OpenRgn();
InsetRect( &windowRect, -4, -4 );
windowRect.top -= 16; /* add room for the title bar */
MoveTo( windowRect.left, windowRect.top );
LineTo( windowRect.left, windowRect.bottom-2 );
LineTo( windowRect.left+2, windowRect.bottom );
LineTo( windowRect.right, windowRect.bottom );
LineTo( windowRect.right, windowRect.top+2 );
LineTo( windowRect.right-2, windowRect.top );
LineTo( windowRect.left, windowRect.top );
CloseRgn( (*(WindowPeek)window).strucRgn );
break;
case ( dBoxProc ): /* dialog box variation */
OpenRgn();
InsetRect( &windowRect, -8, -8 );
MoveTo( windowRect.left, windowRect.top );
LineTo( windowRect.left, windowRect.bottom-2 );
LineTo( windowRect.left+2, windowRect.bottom );
LineTo( windowRect.right, windowRect.bottom );
LineTo( windowRect.right, windowRect.top+2 );
LineTo( windowRect.right-2, windowRect.top );
LineTo( windowRect.left, windowRect.top );
CloseRgn( (*(WindowPeek)window).strucRgn );
break;
case ( plainDBox ): /* plain box variation */
InsetRect( &windowRect, -1, -1 );
RectRgn( (*(WindowPeek)window).strucRgn, &windowRect );
break;
case ( altDBoxProc ): /* shadow box variation */
OpenRgn();
InsetRect( &windowRect, -1, -1 );
MoveTo( windowRect.left, windowRect.top );
LineTo( windowRect.left, windowRect.bottom );
LineTo( windowRect.left+2, windowRect.bottom );
LineTo( windowRect.left+2, windowRect.bottom+2 );
LineTo( windowRect.right+2, windowRect.bottom+2 );
LineTo( windowRect.right+2, windowRect.top+2 );
LineTo( windowRect.right, windowRect.top+2 );
LineTo( windowRect.right, windowRect.top );
LineTo( windowRect.left, windowRect.top );
CloseRgn( (*(WindowPeek)window).strucRgn );
break;
}
} /* end of calculateMyWindow() */
/*╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
draw the growing outline, the pen is already set
╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤*/
growMyWindow( variation, window, parameter )
short variation; /* variation code on this type window */
WindowPtr window; /* pointer to the window */
long parameter; /* parameter used for many things */
{
Rect growingRect;
growingRect = *(Rect *)parameter;
growingRect.top -= 20; /* out to full size */
growingRect.left -= 4;
growingRect.bottom += 4;
growingRect.right += 4;
FrameRect( &growingRect ); /* the frame */
growingRect.top += 19;
MoveTo( growingRect.left, growingRect.top ); /* the title bar area */
LineTo( growingRect.right, growingRect.top );
MoveTo( growingRect.right - 19, growingRect.top ); /* the scroll area */
LineTo( growingRect.right - 19, growingRect.bottom );
MoveTo( growingRect.left, growingRect.bottom - 19 );
LineTo( growingRect.right, growingRect.bottom - 19 );
} /* end of growMyWindow() */
/*╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
draw the size box and the scroll frame
╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤*/
drawGrowIcon( variation, window, parameter )
short variation; /* variation code on this type window */
WindowPtr window; /* pointer to the window */
long parameter; /* parameter used for many things */
{
Rect thisRect;
SetPort( window );
/* ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤ draw scroll bar frame */
thisRect = (*window).portRect;
thisRect.left = thisRect.right - 15;
MoveTo( thisRect.left, thisRect.top );
LineTo( thisRect.left, thisRect.bottom );
thisRect.top = thisRect.bottom - 15;
thisRect.left = (*window).portRect.left;
MoveTo( thisRect.left, thisRect.top );
LineTo( thisRect.right, thisRect.top );
/* ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤ draw the sizing box */
thisRect = (*window).portRect;
thisRect.left = thisRect.right - 14;
thisRect.top = thisRect.bottom - 14;
EraseRect( &thisRect ); /* clear it out in case program doesn't */
if ( (*(WindowPeek)window).hilited ) { /* the size box chevrons */
thisRect.top += 4;
thisRect.left += 4;
thisRect.bottom -= 2;
thisRect.right -= 2;
PaintRect( &thisRect );
OffsetRect( &thisRect, -2, -2 );
thisRect.right -= 1;
thisRect.bottom -= 1;
EraseRect( &thisRect );
thisRect.right -= 1;
thisRect.bottom -= 1;
PaintRect( &thisRect );
thisRect.right -= 3;
thisRect.bottom -= 3;
EraseRect( &thisRect );
}
} /* end of drawGrowIcon() */
/*╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
set up the window
╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤*/
setupWindow( variation, window, parameter )
short variation; /* variation code on this type window */
WindowPtr window; /* pointer to the window */
long parameter; /* parameter used for many things */
{
SysEnvRec thisWorld;
OSErr error;
GDHandle thisDevice;
Rect thisRect;
GrafPtr savedPort;
GrafPort tempPort;
(*(WindowPeek)window).dataHandle = NewHandle( (long)sizeof(WSDRecord) );
if ( variation == (documentProc+8) ) {
(*(WindowPeek)window).spareFlag = true;
if ( (*(WindowPeek)window).dataHandle != nil ) {
error = SysEnvirons( 1, &thisWorld );
/* if ( error == noErr && thisWorld.hasColorQD ) {
thisDevice = GetMainDevice();
thisRect = (**thisDevice).gdRect;
thisRect.top += MBarHeight;
} else */ {
GetPort(&savedPort); /* finding screenBits w/o globals */
OpenPort(&tempPort);
thisRect = tempPort.portRect;
SetPort(savedPort);
ClosePort(&tempPort);
thisRect.top += MBarHeight; /* make way for the menubar */
}
InsetRect( &thisRect, 4, 4 ); /* make way for edges */
thisRect.top += 16; /* make way for what's left of title */
(**(WSDHandle)(*(WindowPeek)window).dataHandle).stdState = thisRect;
(**(WSDHandle)(*(WindowPeek)window).dataHandle).userState = thisRect;
}
} else {
(*(WindowPeek)window).spareFlag = false;
/* (*(WindowPeek)window).dataHandle = nil; */
}
buttonState = false;
} /* end of setupWindow() */
/*╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
kill the window
╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤*/
killWindow( variation, window, parameter )
short variation; /* variation code on this type window */
WindowPtr window; /* pointer to the window */
long parameter; /* parameter used for many things */
{
Rect growingRect;
/* if ( (*(WindowPeek)window).spareFlag ) { */
DisposHandle( (*(WindowPeek)window).dataHandle );
(*(WindowPeek)window).dataHandle = nil;
/* } */
} /* end of setupWindow() */